<template>
  <div class="project1Detail">
    <cheader :pageIndex="project"></cheader>
    <div class="banner" :style="{backgroundImage: 'url('+ bg +')',  backgroundColor: bannerBg[project]}">
      <div class="content">
        <div class="p1-title">
          <div class="tWrap">
            <div class="t">
              <!-- <img src="@/common/img/ball1.png" alt=""> -->
              <img :src="ball" alt="">
              <!-- <img :src="'../../common/img/common/ball'+ (parseInt(project)+1) +'.png'" alt=""> -->
              <h2>“{{titleArr[project][blc].title1}}”</h2>
              <i></i>
            </div>
          </div>
          <div class="bWrap">
            <div class="b">
              <h3>{{titleArr[project][blc].title2}}</h3>
              <i></i>
            </div>
          </div>
        </div>
        <span class="goProject" @click="goProject">返回专题页 ></span>
      </div>
    </div>
    <div class="content" ref="count">
      <div class="lPart">
        <h1>{{artileObj.title}}</h1>
        <div v-if="artileObj.dcover && artileObj.ctype != 1">
          <viewer>
            <img :src="artileObj.dcover" alt="" class="dcover">
          </viewer>
        </div>
        <div class="videoWrap" v-if="artileObj.ctype == 1 && artileObj.url">
          <video :src="artileObj.url" controls="controls" object-fit:="" fill="" class="mv"></video>
        </div>
        <div class="audioWrap" v-if="artileObj.ctype == 2 && artileObj.url">
          <audio :src="artileObj.url" controls="controls"></audio>
        </div>
        <h2 v-if="artileObj.writer">作者：{{artileObj.writer}}</h2>
        <div v-html="artileObj.description" class="rich"></div>
      </div>
      <div class="rPart" v-if="barShow">
        <!-- <h2>相关作品</h2>
        <ul>
          <li :style="{backgroundImage: 'url('+ item.cover +')'}" v-for="item in relateArr" :key="item.id" :data-did="item.id" @click.stop="jump">
            <div class="cover" :data-did="item.id">
              <h3 :data-did="item.id">{{item.title.length>8?item.title.substring(0, 8)+'...' : item.title}}</h3>
            </div>
          </li>
        </ul> -->
        <div class="prev other" v-if="prevItem.title">
          <h3>上一篇</h3>
          <div class="blc" :style="{backgroundImage: 'url('+ prevItem.cover +')'}" :data-did="prevItem.id" @click.stop="jump">
            <div class="cover" :data-did="prevItem.id" @click.stop="jump">
              <h4 :data-did="prevItem.id" @click.stop="jump">{{prevItem.title.length>8?prevItem.title.substring(0, 8)+'...' : prevItem.title}}</h4>
            </div>
          </div>
        </div>
        <div class="prev other" v-if="nextItem.title">
          <h3>下一篇</h3>
          <div class="blc" :style="{backgroundImage: 'url('+ nextItem.cover +')'}" :data-did="nextItem.id" @click.stop="jump">
            <div class="cover" :data-did="nextItem.id" @click.stop="jump">
              <h4 :data-did="nextItem.id" @click.stop="jump">{{nextItem.title.length>8?nextItem.title.substring(0, 8)+'...' : nextItem.title}}</h4>
            </div>
          </div>
        </div>
      </div>
    </div>
    <cfooter v-if="artileObj.title"></cfooter>
  </div>
</template>
<script>
import cheader from '@/components/cheader/cheader'
import cfooter from '@/components/cfooter/cfooter'
import api from '@/common/js/api'
export default {
  data () {
    return {
      pageIndex: 0,
      bg: require('@/common/img/bg.png'),
      ball: '',
      project: 0,
      blc: '',
      bannerBg: [
        '#59bed9',
        '#d2964f',
        '#57a9d5',
        '#2e9a9a'
      ],
      titleArr: [
        // 专题一
        [
          {
            title1: '以笔为旗, 书写大爱',
            title2: '书法作品大合集'
          },
          {
            title1: '丹青妙手，聚暖生春',
            title2: '平面绘画作品大合集'
          },
          {
            title1: '字字珠玑，心灯长明',
            title2: '诗词作品'
          },
          {
            title1: '匠心独具，心系疫情',
            title2: '原创MV作品大合集'
          }
        ],
        // 专题二
        [
          {
            title1: '桃李不言，大爱交大',
            title2: ''
          },
          {
            title1: '战疫一线，唱响基层',
            title2: ''
          },
          {
            title1: '青春战疫，百炼成钢',
            title2: ''
          }
        ],
        // 专题三
        [
          {
            title1: '康康战疫记',
            title2: ''
          },
          {
            title1: '科技战疫',
            title2: ''
          },
          {
            title1: '建言献策',
            title2: ''
          },
          {
            title1: '科普知识',
            title2: ''
          }
        ],
        // 专题四
        [
          {
            title1: '躬先表率',
            title2: '优秀共产党员'
          },
          {
            title1: '医者仁心',
            title2: '照片集锦'
          },
          {
            title1: '心得感悟',
            title2: '手稿集锦'
          },
          {
            title1: '感动你我',
            title2: '专题短片'
          }
        ]
      ],
      did: '',
      postType: 0,
      artileObj: {},
      relateArr: [],
      prevItem: {},
      nextItem: {},
      barShow: true
    }
  },
  created () {
    this.project = this.$route.query.project
    this.blc = this.$route.query.blc
    this.did = this.$route.query.did
    api.articleDetail(this.did).then(res => {
      if (res.data.result === '0') {
        this.artileObj = res.data.data.detail
        this.relateArr = res.data.data.relate
        this.nextItem = res.data.data.next
        this.prevItem = res.data.data.previous
      }
    })
    if (this.project === 1 && this.blc === 0) {
      this.barShow = false
    }
  },
  mounted () {
    this.ball = require('../../common/img/ball' + (parseInt(this.project) + 1) + '.png')
  },
  updated () {
    let wH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
    this.$refs.count.style.minHeight = wH - 369 + 'px'
  },
  methods: {
    goProject () {
      this.$router.back(-1)
      // this.$router.push({
      //   name: 'project' + (parseInt(this.project) + 1)
      // })
    },
    // 去文章详情页 (专题几，第几个模块, 后端参数id, 后端参数id)
    goToDetail (project, blc, did) {
      this.$router.push({
        name: 'projectDetail',
        query: {
          project: project,
          blc: blc,
          did: did
        }
      })
    },
    jump (e) {
      let did = e.target.dataset.did
      this.did = did
      console.log(this.did)
      this.goToDetail(this.project, this.blc, this.did)
    }
  },
  watch: {
    '$route' (to, from) {
      this.$router.go(0)
    }
  },
  components: {
    cheader,
    cfooter
  }
}
</script>
<style lang="scss" scoped>
  .project1Detail {
    .banner {
      height: 278px;
      background: center center no-repeat;
      // background-color: #000;
      width: 100%;
      .content {
        // background: #ccc;
        width: 1100px;
        height: 100%;
        margin: 0 auto;
        position: relative;
        .p1-title {
          position: absolute;
          left: 0px;
          bottom: 40px;
          .t {
            height: 50px;
            position: relative;
            display: inline-block;
            img {
              position: absolute;
              left: 0;
              top: 0;
            }
            h2 {
              font-size: 28px;
              color: #fff;
              position: relative;
              top: 16px;
              // margin-left: 5px;
              font-weight: bold;
            }
            i {
              width: 6px;
              height: 6px;
              position: absolute;
              right: -3px;
              bottom: 4px;
              background-color: #ffe75f;
            }
          }
          .b {
            margin-top: 20px;
            display: flex;
            justify-content: space-between;
            position: relative;
            h3 {
              font-size: 20px;
              color: #fff;
              position: relative;
              z-index: 3;
            }
            i {
              color: #fff;
              font-size: 20px;
              font-style: normal;
              cursor: pointer;
            }
          }
        }
        .goProject {
          cursor: pointer;
          height: 20px;
          line-height: 20px;
          // background-color: red;
          color: #fff;
          position: absolute;
          bottom: 49px;
          right: 12px;
        }
      }
    }
    .content {
      width: 1100px;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      .lPart {
        width: 818px;
        padding-bottom: 40px;
        // background: green;
        .dcover {
          max-width: 818px;
          display: block;
          margin: 0 auto 40px;
          cursor: pointer;
        }
        h1 {
          margin-top: 40px;
          color: #282828;
          font-size: 24px;
          font-weight: bold;
          line-height: 30px;
          margin-bottom: 30px;
        }
        h2 {
          font-size: 18px;
          color: #3e3e3e;
          margin-bottom: 20px;
        }
        .rich {
          line-height: 30px;
        }
        .videoWrap {
          margin-bottom: 20px;
          video {
            width: auto;
            display: block;
            margin: 0 auto;
            border-radius: 10px;
            max-width: 818px;
            max-height: 500px;
          }
        }
      }
      .rPart {
        width: 260px;
        // background-color: blue;
        h2 {
          margin-top: 45px;
          font-size: 18px;
          color: #444;
          margin-bottom: 36px;
        }
        ul {
          li {
            width: 260px;
            height: 146px;
            background-color: #ccc;
            border-radius: 10px;
            margin-bottom: 24px;
            background: center no-repeat;
            background-size: cover;
            position: relative;
            z-index: 1;
            overflow: hidden;
            cursor: pointer;
            .cover {
              position: absolute;
              width: 260px;
              height: 73px;
              left: 0;
              bottom: 0;
              z-index: 2;
              background-image: linear-gradient(transparent, #5a5a5a);
              h3 {
                color: #fff;
                position: absolute;
                bottom: 10px;
                left: 10px;
              }
            }
          }
        }
        .other {
          h3 {
            margin-top: 45px;
            font-size: 18px;
            color: #444;
            margin-bottom: 20px;
          }
          .blc {
            width: 260px;
            height: 146px;
            background-color: #ccc;
            border-radius: 10px;
            margin-bottom: 24px;
            background: center no-repeat;
            background-size: cover;
            position: relative;
            z-index: 1;
            overflow: hidden;
            cursor: pointer;
            .cover {
              position: absolute;
              width: 260px;
              height: 73px;
              left: 0;
              bottom: 0;
              z-index: 2;
              background-image: linear-gradient(transparent, #000);
              h4 {
                color: #fff;
                position: absolute;
                bottom: 10px;
                left: 10px;
              }
            }
          }
        }
      }
    }
    .cfooter {
      background-color: #e5e5e5;
      >>> span {
        color: #595959;
      }
    }
  }

</style>
